#include <stdio.h>
#include <string.h>

#ifndef __plugin__
#include "plugin.h"
#endif

//----------------------------------------------------------------------------- 
PluginProgram::PluginProgram ()
{
	fOut = 0.0;
	strcpy (name, "Init");
}

//-----------------------------------------------------------------------------
Plugin::Plugin (audioMasterCallback audioMaster)
	: AudioEffectX (audioMaster, kNumPrograms, kNumParams)
{
	programs = new PluginProgram[numPrograms];
	fOut = 0.0f;

	if (programs)
		setProgram (0);

	// This plugin class is mono by default
	// and the numebr of channels is matter of SurroundPlugin class

	setNumInputs (1);	// mono input
	setNumOutputs (1);	// stereo output

	setUniqueID ('NM02');	// this should be unique, use the Steinberg web page for plugin Id registration

	resume ();		// flush buffer
}

//------------------------------------------------------------------------
Plugin::~Plugin ()
{
	if (programs)
		delete[] programs;
}

//------------------------------------------------------------------------
void Plugin::setProgram (VstInt32 program)
{
	PluginProgram* ap = &programs[program];

	curProgram = program;
	setParameter (kOut, ap->fOut);
}

//------------------------------------------------------------------------
void Plugin::setProgramName (char *name)
{
	strcpy (programs[curProgram].name, name);
}

//------------------------------------------------------------------------
void Plugin::getProgramName (char *name)
{
	if (!strcmp (programs[curProgram].name, "Init"))
		sprintf (name, "%s %d", programs[curProgram].name, curProgram + 1);
	else
		strcpy (name, programs[curProgram].name);
}

//-----------------------------------------------------------------------------------------
bool Plugin::getProgramNameIndexed (VstInt32 category, VstInt32 index, char* text)
{
	if (index < kNumPrograms)
	{
		strcpy (text, programs[index].name);
		return true;
	}
	return false;
}

//------------------------------------------------------------------------
void Plugin::resume ()
{
	AudioEffectX::resume ();
}

//------------------------------------------------------------------------
void Plugin::setParameter (VstInt32 index, float value)
{
	PluginProgram* ap = &programs[curProgram];

	switch (index)
	{
		case kOut : fOut = ap->fOut = value; break;
	}
}

//------------------------------------------------------------------------
float Plugin::getParameter (VstInt32 index)
{
	float v = 0;

	switch (index)
	{
		case kOut :      v = fOut;		break;
	}
	return v;
}

//------------------------------------------------------------------------
void Plugin::getParameterName (VstInt32 index, char *label)
{
	switch (index)
	{
		case kOut :      strcpy (label, "Gain");		break;
	}
}

//------------------------------------------------------------------------
void Plugin::getParameterDisplay (VstInt32 index, char *text)
{
	switch (index)
	{
		case kOut :      dB2string (fOut, text, kVstMaxParamStrLen);			break;
	}
}

//------------------------------------------------------------------------
void Plugin::getParameterLabel (VstInt32 index, char *label)
{
	switch (index)
	{
		case kOut :      strcpy (label, "dB");		break;
	}
}

//------------------------------------------------------------------------
bool Plugin::getEffectName (char* name)
{
	strcpy (name, "NM-02");
	return true;
}

//------------------------------------------------------------------------
bool Plugin::getProductString (char* text)
{
	strcpy (text, "NM-02 Volume Maximizer");
	return true;
}

//------------------------------------------------------------------------
bool Plugin::getVendorString (char* text)
{
	strcpy (text, "Bc. Vojtech Prehnal");
	return true;
}

void Plugin::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames)
{
	// All the processing is in stereoplugin
}
